package com.atguigu.edu.service.impl;

import com.atguigu.edu.entity.Comment;
import com.atguigu.edu.mapper.CommentMapper;
import com.atguigu.edu.service.CommentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author ld
 * @since 2022-08-24
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    //分页展示评论信息
    @Override
    public Map<String, Object> pageInfo(Page<Comment> pageInfo, LambdaQueryWrapper<Comment> queryWrapper) {

        baseMapper.selectPage(pageInfo,queryWrapper);
        Map<String,Object> map=new HashMap<>();
        List<Comment> records = pageInfo.getRecords();
        long current = pageInfo.getCurrent();
        long size = pageInfo.getSize();
        long pages = pageInfo.getPages();
        long total = pageInfo.getTotal();
        boolean hasPrevious = pageInfo.hasPrevious();
        boolean hasNext = pageInfo.hasNext();

        map.put("records",records);
        map.put("current",current);
        map.put("size",size);
        map.put("pages",pages);
        map.put("total",total);
        map.put("hasPrevious",hasPrevious);
        map.put("hasNext",hasNext);

        return map;
    }

}
